﻿using Microsoft.AspNetCore.Mvc;
using StarsAdmin.Application.OperationLog.Dtos;
using StarsAdmin.Application.OperationLog.Services;
using StarsAdmin.Core.Attributes;
using StarsAdmin.Core.Models;
using StarsAdmin.Web.Core.Conttrollers;
using System.ComponentModel.DataAnnotations;

namespace StarsAdmin.WebApi.Conttrollers
{
    /// <summary>
    /// 操作日志管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Order(11)]
    public class OperationLogController : BaseController
    {
        private readonly IOperationLogService _operationLogService;

        public OperationLogController(IOperationLogService operationLogService)
        {
            _operationLogService = operationLogService;
        }

        /// <summary>
        /// 获取所有
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultModel<List<OperationLogDto>>> GetAllAsync([FromQuery] BaseQueryInput input)
        {
            return (await _operationLogService.GetAllAsync(input)).ResultFormat();
        }

        /// <summary>
        /// 分页获取
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultModel<Page<OperationLogDto>>> GetPageAsync([FromQuery] PageQueryInput input)
        {
            return (await _operationLogService.GetPageAsync(input)).ResultFormat();
        }

        /// <summary>
        /// 根据Id获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultModel<OperationLogDto>> GetByIdAsync([Required] long id)
        {
            return (await _operationLogService.GetByIdAsync(id)).ResultFormat("没有找到该条数据", 404);
        }

        /// <summary>
        /// 根据Id集合获取数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultModel<List<OperationLogDto>>> GetByIdsAsync([FromQuery] BaseIdsInput input)
        {
            return (await _operationLogService.GetByIdsAsync(input.Ids)).ResultFormat();
        }
    }
}